home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / logrecs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  9.6 KB  |  413 lines

  1. #ifndef _LOGRECS_H_
  2. #define _LOGRECS_H_
  3. #ifndef __LOGRECS_H__
  4. #define __LOGRECS_H__
  5. /*
  6.  *   $RCSfile: logrecs.h,v $  
  7.  *   $Revision: 1.1.1.1 $  
  8.  *   $Date: 1996/05/04 21:55:08 $      
  9.  */ 
  10.  
  11. /**********************************************************************
  12. * EXODUS Database Toolkit Software
  13. * Copyright (c) 1991 Computer Sciences Department, University of
  14. *                    Wisconsin -- Madison
  15. * All Rights Reserved.
  16. *
  17. * Permission to use, copy, modify and distribute this software and its
  18. * documentation is hereby granted, provided that both the copyright
  19. * notice and this permission notice appear in all copies of the
  20. * software, derivative works or modified versions, and any portions
  21. * thereof, and that both notices appear in supporting documentation.
  22. *
  23. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  24. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  25. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  26. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  27. *
  28. * The EXODUS Project Group requests users of this software to return 
  29. * any improvements or extensions that they make to:
  30. *
  31. *   EXODUS Project Group 
  32. *     c/o David J. DeWitt and Michael J. Carey
  33. *   Computer Sciences Department
  34. *   University of Wisconsin -- Madison
  35. *   Madison, WI 53706
  36. *
  37. *     or exodus@cs.wisc.edu
  38. *
  39. * In addition, the EXODUS Project Group requests that users grant the 
  40. * Computer Sciences Department rights to redistribute these changes.
  41. **********************************************************************/
  42.  
  43. /*
  44.  *    define the maximum number of images that can be passed
  45.  *    in the write log call.  Also the max size of a log record must
  46.  *    fit in a max page since these are used to buffer log records
  47.  *    which span multiple pages.  A sanity check is performed in
  48.  *    openLogFile().
  49.  */
  50. #define MAX_LOGREC_IMAGES        3
  51. #define LOGREC_BUF_PAGE2SIZE    ( MAX_PAGE2SIZE  )
  52. #define MAX_LOGREC_LEN            ( MAX_PAGESIZE  )
  53.  
  54.  
  55. /*
  56.  *    Magic numbers for log records are only two bytes to save space.
  57.  */
  58. typedef UTWO MAGICLOG;
  59.  
  60. /*
  61.  *    define the structure of a log record
  62.  *    note that a four must be the last member for alignment purposes
  63.  */
  64. typedef struct    {
  65.  
  66.     MAGICLOG    magic;                /* magic number of this record    */
  67.     UTWO        length;                /* size of the log record        */
  68.     UONE        type;                /* type of record entry            */
  69.     UONE        imageCount;            /* count of record images        */
  70.     UONE        action;                /* client specific action        */
  71.     UONE        flags;
  72.     TID            tid;                /* tid of this record            */
  73.     LSNOFFSET    previousLSN;        /* previous LSN for transaction    */
  74.     LSNOFFSET    nextUndoLSN;        /* for compensation log records    */
  75.     LSN            recordLSN;            /* lsn of this record            */
  76.     LRC            actionLRC;            /* lrc of this action on page     */
  77.     PID            actionPid;            /* pid the action applies to    */
  78.     /*FID            actionFid;    */        /* file page is a member of    */
  79.     UTWO        imageOffset[MAX_LOGREC_IMAGES];    /* offset of the images            */
  80.     UTWO        imageSize[MAX_LOGREC_IMAGES];    /* size of the images            */
  81.     /* UFOUR        delimiter;    */        /* for debugging ease        */
  82.  
  83. } LOGRECORDHDR;
  84.  
  85.  
  86. /*
  87.  *    define the magic numbers of a log record
  88.  */
  89. #define LOGRECORD_MAGIC        0xbbbb
  90. #define LOGRECORD_DELIMIT    0xcccccccc
  91.  
  92. #define MAX_LOGIMAGE_LEN    (MAX_LOGREC_LEN - sizeof(LOGRECORDHDR))
  93.  
  94. /*
  95.  *    define the flags for the log records
  96.  */
  97. #define REDO_ONLY        0x1
  98. #define REDO_ALWAYS        0x2
  99. #define UNDO_ONLY        0x4
  100.  
  101. /*
  102.  *    define the structure for the log page header
  103.  */
  104. typedef struct    {
  105.  
  106.     MAGIC        magic;
  107.     SHORTPID    pageNumber;
  108.     UFOUR        wrapCount;
  109.     SHORTPID    lastRecord;
  110.  
  111. } LOGPAGEHDR;
  112.  
  113.  
  114. /*
  115.  *    define the magic number of a log page
  116.  */
  117. #define LOGPAGE_MAGIC        0xaaaaaaaa
  118.  
  119.  
  120. /*
  121.  *    define the initial wrap count of the log
  122.  */
  123. #define NULL_LOG_WRAP_COUNT        0
  124. #define INIT_LOG_WRAP_COUNT        1
  125.  
  126.  
  127. /*
  128.  *    define the null lastRecord pointer
  129.  */
  130. #define NULL_LAST_RECORD        0
  131.  
  132. #define VOID void
  133.  
  134.  
  135. /*
  136.  *    define a record type that is used to pass
  137.  *    information into a write log call for the server
  138.  */
  139. typedef struct    {
  140.  
  141.     UONE    action;
  142.     UONE    type;
  143.     UONE    flags;
  144.     UONE    imageCount;
  145.     UTWO    imageSize[MAX_LOGREC_IMAGES];
  146.     VOID    *imageData[MAX_LOGREC_IMAGES];
  147.     UFOUR    nextUndoLSN;
  148.     PID        *actionPid;
  149.     LRC        *actionLRC;
  150.     /*FID        *actionFid;*/
  151.  
  152. } LOGRECORDINFO;
  153.  
  154.  
  155. /*
  156.  *    define a record type that is used to pass
  157.  *    information into a write log call for the client
  158.  */
  159. typedef struct    {
  160.  
  161.     UONE    action;
  162.     UONE    type;
  163.     UONE    flags;
  164.     UONE    imageCount;
  165.     UTWO    imageSize[MAX_LOGREC_IMAGES];
  166.     VOID    *imageData[MAX_LOGREC_IMAGES];
  167.     UFOUR    nextUndoLSN;
  168.     PID        actionPid;
  169.     LRC        actionLRC;
  170.  
  171. } CLIENTLOGRECORDINFO;
  172.  
  173.  
  174. /*
  175.  *    define flags
  176.  */
  177. #define LOG_FORCE    0x1
  178.  
  179.  
  180. /*
  181.  *    define the types of log records
  182.  */
  183. #define LOG_REC_TYPE_NULL                0
  184. #define LOG_REC_TYPE_USER                1
  185. #define LOG_REC_TYPE_ABORT                2
  186. #define LOG_REC_TYPE_COMMIT                3
  187. #define LOG_REC_TYPE_CHECKPOINT            4
  188. #define LOG_REC_TYPE_COMPENSATION        5
  189. #define LOG_REC_TYPE_DIRTYPAGELIST        6
  190. #define LOG_REC_TYPE_MOUNT_VOLUME        7
  191. #define LOG_REC_TYPE_DISMOUNT_VOLUME    8
  192. #define LOG_REC_TYPE_USER_COMPENSATION  9
  193. #define LOG_REC_TYPE_SERVER_PREPARE       10    /* for distr trans */
  194. #define LOG_REC_TYPE_COORD_PREPARE       11    /* for distr trans */
  195. #define LOG_REC_TYPE_END               12    /* for distr trans */
  196.  
  197.  
  198. /*
  199.  *    fixed length (image[0]) data for write/insert/delete/append
  200.  */
  201. typedef struct  {
  202.     UNIQUE        unique;    /* unique field of oid             */
  203.     SLOTINDEX    slot;    /* slot field of oid (2 bytes)    */
  204.     UTWO        start;  /* start location of operation    */
  205. } WRITEINFO;
  206.  
  207. /*
  208.  *    fixed length (image[0]) data for write/insert/delete/append
  209.  *    This is for those operations where the data is not logged
  210.  */
  211. typedef struct  {
  212.     WRITEINFO    common;
  213.     UTWO        size;      /* size of operation            */
  214. } FULLWRITEINFO;
  215.  
  216. /*
  217.  *    fixed length (image[0]) data for write of large objects
  218.  */
  219. typedef struct  {
  220.     UTWO    start;
  221.     UTWO    size;
  222.     TWO        rootSlot;
  223.     UTWO    prevSize;
  224. } LGWRITEINFO;
  225.  
  226. /*
  227.  *    fixed length (image[0]) data for update of large obj slots
  228.  */
  229. typedef struct  {
  230.     UTWO    start;
  231.     TWO        rootSlot;
  232.     FOUR    size;
  233. } LGSLOTUPDATEINFO;
  234.  
  235.  
  236. /*
  237.  *    Page allocation/deallocation info (image[0] for logging (de)alloc)
  238.  */
  239. typedef struct {
  240.     FOUR        numPages;
  241.     PAGE2SIZE    page2size;
  242.     SHORTPID    firstBitmapPage;
  243.     SHORTPID    volumeHdrPage;
  244.     LRC            headerLRC;             /* volume header LRC     */
  245. } PAGEALLOCINFO;
  246.  
  247. /*
  248.  *    Information for root entry setting log record
  249.  */
  250. typedef struct {
  251.     ONE        oldFlags;
  252.     UTWO    nameLen;
  253.     UONE    name[MAX_ROOTNAME_SIZE];
  254. } ROOTENTRYLOGINFO;
  255.  
  256. /*
  257.  *    define the body of a checkpoint record
  258.  */
  259. typedef struct    {
  260.  
  261.     UTWO        numActiveTrans;
  262.     UTWO        mountedVolCount;
  263.     UFOUR        numDirtyPages;
  264.     UFOUR        wrapCount;
  265.  
  266. } CHECKPOINTINFO;
  267.  
  268. /*
  269.  *    define the body of a checkpoint dirty page table record
  270.  *    The checkpoint DPT is sent as a series of log records with
  271.  *    this struct as the first image and a list of DPT entries as
  272.  *    the second image.  Since is may take multiple checkpointDPT
  273.  *    records to record the entire DPT, the recordNum field orders
  274.  *    these records.
  275.  */
  276. typedef struct    {
  277.  
  278.     UTWO        numDirtyPages;    /* # of pages in this record     */
  279.     UTWO        recordNum;        /* sequence # of this record    */
  280.  
  281. } CHECKPOINTDPTINFO;
  282.  
  283.  
  284. /*
  285.  *    define the state info for a transaction in checkpoint
  286.  */
  287. typedef struct {
  288.  
  289.     ONE            state;
  290.     TID            tid;
  291.     LSN            firstLSN;
  292.     LSNOFFSET    lastLSN;
  293.     LSNOFFSET    nextUndoLSN;
  294.     /*
  295.      *    for distr trans
  296.      */
  297.     UFOUR        numServers;
  298.     LSN            prepareLSN;
  299.  
  300. } CHECKTRANS;
  301.  
  302.  
  303. /*
  304.  *    define the pointer to the checkpoint record
  305.  */
  306. typedef struct    {
  307.  
  308.     MAGIC        magic;
  309.     UFOUR        wrapCount;
  310.     LSN            checkRecordLSN;
  311.     UFOUR        oldestDirtyLSN;
  312.  
  313. } CHECKPOINTMASTER;
  314.  
  315.  
  316. #define CHECKPOINTMASTER_MAGIC    0x04c6745a
  317.  
  318.  
  319. /*
  320.  *    define the magic checking macros
  321.  */
  322. #define CHECK_LOGRECORD_MAGIC(_record)            \
  323.     ((_record)->magic != LOGRECORD_MAGIC)
  324.  
  325.  
  326. #define CHECK_LOGPAGE_MAGIC(_header)            \
  327.     ((_header)->magic != LOGPAGE_MAGIC)
  328.  
  329.  
  330. #define REMAIN_BYTES(_openLog, _offset)    (_openLog->pagesize - (_offset + sizeof(FOUR)))
  331.  
  332.  
  333. #ifdef DEBUG
  334.     /*
  335.      *    define a macro to get at the ith element of the log record
  336.      */
  337. #    define GET_LOG_IMAGE(_recordHeader, index)                    \
  338.                                                                 \
  339.         ( ( (index < (_recordHeader)->imageCount) && (index >= 0) && (index < MAX_LOGREC_IMAGES)) ? \
  340.                 (((char *) (_recordHeader)) + (_recordHeader)->imageOffset[index] + sizeof(LOGRECORDHDR))    : \
  341.                 (SM_ERROR(TYPE_FATAL, esmINTERNAL), (char*) NULL))
  342.  
  343. #else
  344.  
  345.     /*
  346.      *    define a macro to get at the ith element of the log record
  347.      */
  348. #    define GET_LOG_IMAGE(_recordHeader, index)                    \
  349.                                                                 \
  350.         (((char *) _recordHeader) + (_recordHeader)->imageOffset[index] + sizeof(LOGRECORDHDR))
  351. #endif
  352.  
  353.  
  354. #ifdef DEBUG
  355.     /*
  356.      *    define a macro getting the size of the ith element of the 
  357.      *    log record
  358.      */
  359. #    define GET_LOG_IMAGE_SIZE(_recordHeader, index)                    \
  360.                                                                 \
  361.         ( ( (index < (_recordHeader)->imageCount) && (index >= 0) ) ? \
  362.                 ( (_recordHeader)->imageSize[index])    : \
  363.                 (SM_ERROR(TYPE_FATAL, esmINTERNAL), -1))
  364.  
  365. #else
  366.  
  367.     /*
  368.      *    define a macro getting the size of the ith element of the 
  369.      *    log record
  370.      */
  371. #    define GET_LOG_IMAGE_SIZE(_recordHeader, index)                    \
  372.                                                                 \
  373.         ( (_recordHeader)->imageSize[index])
  374. #endif
  375.  
  376.  
  377. /*
  378.  *    define LSN manipulation macros
  379.  */
  380. #define LSN_TO_BLOCK(_lsn, _openLog)        \
  381.     ((_openLog)->logFileAddr + ( ((_lsn) >> (_openLog)->page2size) * (_openLog)->blocksPerPage))
  382.  
  383.  
  384. #define LOG_PAGE_TO_BLOCK(_page, _openLog)        \
  385.     ((_openLog)->logFileAddr + ((_page) * (_openLog)->blocksPerPage))
  386.  
  387.  
  388. #define LSN_TO_LOG_PAGE(_lsn, _openLog)                \
  389.         ((_lsn) >> (_openLog)->page2size)
  390.  
  391.  
  392. #define LOG_PAGE_TO_LSN(_page, _openLog)                \
  393.         ((_page) << (_openLog)->page2size)
  394.  
  395.  
  396. #define LOG_PAGE_OFFSET(_lsn, _openLog)                \
  397.         ((_lsn) & ((_openLog)->pageMask))
  398.  
  399. /*
  400.  *    offset of first lsn on a page
  401.  */
  402. #define FIRST_LSN (sizeof(LOGPAGEHDR))
  403.  
  404. /*
  405.  *    Given a zero lsn return the first valid lsn on a page, otherwise
  406.  *    just return the lsn
  407.  */
  408. #define FIRST_LSN_ON_PAGE(_lsn, _openLog)            \
  409.         ( LOG_PAGE_OFFSET((_lsn), (_openLog)) == 0 ? (_lsn) + FIRST_LSN : (_lsn) )
  410.  
  411. #endif __LOGRECS_H__
  412. #endif /* _LOGRECS_H_ */
  413.